<?php
header("Content-Type: text/html; charset=UTF-8");
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
$conn->set_charset("utf8");


$sql = "SELECT * FROM show_event";
$result = $conn->query($sql);

if (!$result) {
    die("查询失败: " . $conn->error);
}

$data = array();

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $event = array(
            'eventid' => $row['eventid'],
            'title' => $row['title'],
            'starttime' => $row['starttime'],
            'endtime' => $row['endtime'],
            'type' => $row['type'],
            'range' => $row['range'],
            'space' => $row['space'],
            'CreateTime' => $row['CreateTime'],
            'status' => $row['status'],
            'hot' => $row['hot'],
        );
        $data[] = $event;
    }

    print json_encode($data,JSON_UNESCAPED_UNICODE);
} else {
    $response = array('error' => '未找到数据');
    echo json_encode($response);
}

$conn->close();
?>
